var phonecatApp = angular.module('UserService', []);


module.factory( 'UserService', function ( $http, $q ) {

  return {
    get: function getUser( id ) {
      // We create our own promise to return
      var deferred = $q.defer();

      $http.get('/users/'+id).then( function ( user ) {
        $http.get('/accounts/'+user.id).then( function ( acct ) {

          // Add the account info however you want
          user.account = acct;

          // resolve the promise
          deferred.resolve( user );

        }, function getAcctError() { deferred.reject(); } );
      }, function getUserError() { deferred.reject(); } );

      return deferred.promise;
    }
  };
});
UserService.get( $scope.userId ).then( function ( user ) {
  $scope.user = user;
});